/**
 * 要闻动态
 */

//图片前置url
var pre = imageUrl;

//要闻动态
$(function () {

    $.ajax({
        type: "GET",
        url: restUrl + "/index/items",   //接口地址
        dataType: "json",
        data: {
            parentCode: "YWDT",
            loadAll: true,
            needPaging: false,
        },
        success: function (data) {
            if (data.code == 10000) {
                var obj = data;
                for (var i = 0; i < obj.data.rows.length; i++) {
                    var item = obj.data.rows[i];
                    if(item.title.indexOf('\n') >=0){ item.title = item.title.replace(/\n/g,"<br/>");}
                    if(item.copied ==0){
                        $('#contentarea').append('<div class="case_show_list wow fadeInUp"><div class="span5 col-xm-6 col-sm-12"><div class="case_show_pic">'+
                            '<div style="width:100%;height:300px;"><img src="'+ pre + item.cover +'"></div>'+
                            '</div></div><div class="span7 col-xm-6 col-sm-12"><div class="case_show_brief"><h3 class="case_show_brief_title">'+ item.title + '</h3>'+
                            '<div class="case_show_brief_text"><p style="text-align: center">发布时间：'+ formatDate(item.publishDate)+ '&nbsp;&nbsp;&nbsp;&nbsp;作者：'+ item.author+ '</p>'+
                            '<p>'+ item.description + '</p></div><div class="case_show_brief_button"><a href="info.html?id='+ item.id + '&type=YWDT" class="all_button">查看详情</a></div>'+
                            '</div></div></div>');
                    } else {
                        $('#contentarea').append('<div class="case_show_list wow fadeInUp"><div class="span5 col-xm-6 col-sm-12"><div class="case_show_pic">'+
                            '<div style="width:100%;height:300px;"><img src="'+ pre + item.cover +'"></div>'+
                            '</div></div><div class="span7 col-xm-6 col-sm-12"><div class="case_show_brief"><h3 class="case_show_brief_title">'+ item.title + '</h3>'+
                            '<div class="case_show_brief_text"><p style="text-align: center">发布时间：'+ formatDate(item.publishDate)+ '&nbsp;&nbsp;&nbsp;&nbsp;来源：'+ item.copyFrom+ '</p>'+
                            '<p>'+ item.description + '</p></div><div class="case_show_brief_button"><a href="info.html?id='+ item.id + '&type=YWDT" class="all_button">查看详情</a></div>'+
                            '</div></div></div>');
                    }
                }
            } else {
                console.log(data.message)
            }
        },
        error: function (data) {
            console.log(data)
        }
    })
});

//转换日期格式
function formatDate(v) {
    if (/^(-)?\d{1,10}$/.test(v)) {
        v = v * 1000;
    } else if (/^(-)?\d{1,13}$/.test(v)) {
        v = v * 1;
    }
    var dateObj = new Date(v);
    var month = dateObj.getMonth() + 1;
    var day = dateObj.getDate();
    var hours = dateObj.getHours();
    var minutes = dateObj.getMinutes();
    var seconds = dateObj.getSeconds();
    if (month < 10) {
        month = "0" + month;
    }
    if (day < 10) {
        day = "0" + day;
    }
    <!--if(hours<10){-->
    <!--hours = "0" + hours;-->
    <!--}-->
    <!--if(minutes<10){-->
    <!--minutes = "0" + minutes;-->
    <!--}-->
    <!--if(seconds<10){-->
    <!--seconds = "0" + seconds;-->
    <!--}-->
    <!--var UnixTimeToDate = dateObj.getFullYear() + '-' + month + '-' +day + ' ' + hours + ':' + minutes + ':' + seconds;-->
    var UnixTimeToDate = dateObj.getFullYear() + '-' + month + '-' + day + ' ';
    return UnixTimeToDate;
}
